﻿using FrameWork.Core.Infrastructure;
using FrameWork.Data.Interface;
using FrameWork.Data.Mapping;
using FrameWork.Services;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace AncheStart.Converter
{
    public class RealTimeConfigConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (GlobalConstant.RealTimeDataConfigList == null|| GlobalConstant.RealTimeDataConfigList.Count()==0)
            {
                var vals =   EngineContext.Current.Resolve<IRealTimeDataConfigManager>().getAll().Result;
                if (vals != null && vals.Count() > 0)
                {
                   var   RealTimeDataConfigList = new ObservableCollection<RealTimeDataConfig>(vals);
                    GlobalConstant.RealTimeDataConfigList = RealTimeDataConfigList;
                }
            }
            RealTimeDataConfig realTimeDataConfig =  GlobalConstant.RealTimeDataConfigList.FirstOrDefault(s => s.Key == parameter.ToString()) ;
            if (realTimeDataConfig!=null)
            {
                if (realTimeDataConfig.IsVisiable==true)
                {
                    return Visibility.Visible;
                }
            
            }
            return Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
